﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static JMBox.Config.R;

namespace JMBox.Utils
{
    public class MacCheckTool
    {

        public static List<string> GetInterfaceMacAddresses()
        {
            List<string> macAddresses = new List<string>();

            // 获取本地计算机上的所有网络接口
            NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();

            // 遍历每个网络接口
            foreach (NetworkInterface ni in interfaces)
            {
                // 过滤掉非物理接口，例如虚拟机网卡
                if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet ||
                    ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
                {
                    // 获取MAC地址并添加到列表中
                    macAddresses.Add($"{ni.GetPhysicalAddress()}");
                    
                }
            }

            return macAddresses;
        }

        public static bool CheckIsIn(string mac)
        {
            if (string.IsNullOrEmpty(mac))
            {
                return false;
            }
            List<string> macAddresses = GetInterfaceMacAddresses();

            if (macAddresses.Contains(mac))
            {
                return true;
            }
            return false;
        }

        public static bool CanUseBat()
        {
            return CheckIsIn(SymmetricEncryptionTool.getDecrypt(GlobalConfig.SECRET_KEY));
        }

    }
}
